<script setup>
import { ref } from 'vue'

const solarTermCategories = ref([
  {
    season: '春季',
    terms: [
      {
        name: '立春',
        date: '2月4日',
        image: 'https://img.freepik.com/free-photo/cherry-blossoms-spring_1417-1078.jpg',
        description: '立春是二十四节气之首，意味着新的一年开始，万物开始萌发生机。',
        customs: ['吃春饼', '咬春', '迎春'],
        poems: [
          {
            title: '立春',
            author: '王安石',
            content: '律回岁晚冰霜少，春到人间草木知。'
          }
        ],
        activities: ['祭春', '迎春', '踏青']
      },
      {
        name: '雨水',
        date: '2月19日',
        image: 'https://img.freepik.com/free-photo/water-drops-leaf_1150-9207.jpg',
        description: '雨水节气标志着降水开始增多，气温回升加快。',
        customs: ['祈雨', '放生'],
        poems: [
          {
            title: '雨水',
            author: '戴复古',
            content: '春雨晴时春草生，春林春涧响春莺。'
          }
        ],
        activities: ['观雨', '插花']
      }
    ]
  },
  {
    season: '夏季',
    terms: [
      {
        name: '立夏',
        date: '5月6日',
        image: 'https://img.freepik.com/free-photo/summer-landscape_1417-1112.jpg',
        description: '立夏表示进入夏天，万物生长旺盛。',
        customs: ['称人', '晒书', '饮绿茶'],
        poems: [
          {
            title: '立夏',
            author: '白居易',
            content: '夏日长时觉昼长，百花过后绿阴香。'
          }
        ],
        activities: ['赏荷', '纳凉']
      }
    ]
  }
])

const selectedTerm = ref(null)

const showTermDetail = (term) => {
  selectedTerm.value = term
}
</script>

<template>
  <div class="culture-container">
    <div class="culture-header">
      <h1>节气文化</h1>
      <p class="subtitle">探索中国传统二十四节气的文化内涵</p>
    </div>

    <div class="season-sections">
      <div v-for="category in solarTermCategories" :key="category.season" class="season-section">
        <h2 class="season-title">{{ category.season }}</h2>
        <div class="terms-grid">
          <div 
            v-for="term in category.terms" 
            :key="term.name"
            class="term-card"
            @click="showTermDetail(term)"
          >
            <div class="term-image">
              <img :src="term.image" :alt="term.name">
            </div>
            <div class="term-info">
              <h3>{{ term.name }}</h3>
              <p class="term-date">{{ term.date }}</p>
              <p class="term-desc">{{ term.description }}</p>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 节气详情弹窗 -->
    <div v-if="selectedTerm" class="term-detail-modal" @click="selectedTerm = null">
      <div class="modal-content" @click.stop>
        <button class="close-btn" @click="selectedTerm = null">×</button>
        <div class="term-detail-content">
          <div class="term-header">
            <div class="term-main-info">
              <h2>{{ selectedTerm.name }}</h2>
              <p class="term-date">{{ selectedTerm.date }}</p>
            </div>
            <div class="term-image">
              <img :src="selectedTerm.image" :alt="selectedTerm.name">
            </div>
          </div>

          <div class="term-sections">
            <div class="detail-section">
              <h3>节气介绍</h3>
              <p>{{ selectedTerm.description }}</p>
            </div>

            <div class="detail-section">
              <h3>传统习俗</h3>
              <div class="customs-list">
                <span 
                  v-for="(custom, index) in selectedTerm.customs" 
                  :key="index"
                  class="custom-tag"
                >
                  {{ custom }}
                </span>
              </div>
            </div>

            <div class="detail-section">
              <h3>诗词典故</h3>
              <div class="poems-list">
                <div v-for="(poem, index) in selectedTerm.poems" :key="index" class="poem-item">
                  <h4>{{ poem.title }}</h4>
                  <p class="poem-author">{{ poem.author }}</p>
                  <p class="poem-content">{{ poem.content }}</p>
                </div>
              </div>
            </div>

            <div class="detail-section">
              <h3>推荐活动</h3>
              <div class="activities-list">
                <span 
                  v-for="(activity, index) in selectedTerm.activities" 
                  :key="index"
                  class="activity-tag"
                >
                  {{ activity }}
                </span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.culture-container {
  min-height: calc(100vh - 72px);
  padding: 20px;
  max-width: 1800px;
  margin: 0 auto;
}

.culture-header {
  text-align: center;
  margin-bottom: 48px;
}

.culture-header h1 {
  font-size: 36px;
  color: #e3624b;
  font-family: "STKaiti", "KaiTi", serif;
  margin-bottom: 12px;
}

.subtitle {
  color: #666;
  font-size: 16px;
}

.season-section {
  margin-bottom: 48px;
}

.season-title {
  font-size: 24px;
  color: #4a4a4a;
  margin-bottom: 24px;
  font-family: "STKaiti", "KaiTi", serif;
  position: relative;
  padding-left: 16px;
}

.season-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 24px;
  background: #e3624b;
  border-radius: 2px;
}

.terms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
  gap: 24px;
}

.term-card {
  background: white;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
  cursor: pointer;
  transition: transform 0.3s;
}

.term-card:hover {
  transform: translateY(-4px);
}

.term-image {
  height: 240px;
  overflow: hidden;
}

.term-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.term-info {
  padding: 20px;
}

.term-info h3 {
  font-size: 24px;
  color: #4a4a4a;
  margin-bottom: 8px;
  font-family: "STKaiti", "KaiTi", serif;
}

.term-date {
  color: #666;
  margin-bottom: 12px;
}

.term-desc {
  color: #666;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.term-detail-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: white;
  border-radius: 16px;
  width: 90%;
  max-width: 1200px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  padding: 32px;
}

.close-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  background: none;
  border: none;
  font-size: 24px;
  color: #666;
  cursor: pointer;
}

.term-header {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 32px;
  margin-bottom: 32px;
}

.term-main-info h2 {
  font-size: 36px;
  color: #e3624b;
  margin-bottom: 12px;
  font-family: "STKaiti", "KaiTi", serif;
}

.term-sections {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 32px;
}

.detail-section {
  background: #f8f8f8;
  border-radius: 12px;
  padding: 24px;
}

.detail-section h3 {
  font-size: 20px;
  color: #4a4a4a;
  margin-bottom: 16px;
  font-family: "STKaiti", "KaiTi", serif;
}

.customs-list,
.activities-list {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.custom-tag,
.activity-tag {
  padding: 6px 16px;
  background: white;
  border-radius: 20px;
  color: #666;
}

.poems-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.poem-item {
  background: white;
  padding: 16px;
  border-radius: 8px;
}

.poem-item h4 {
  color: #4a4a4a;
  margin-bottom: 8px;
  font-family: "STKaiti", "KaiTi", serif;
}

.poem-author {
  color: #666;
  font-size: 14px;
  margin-bottom: 8px;
}

.poem-content {
  color: #4a4a4a;
  line-height: 1.6;
  font-family: "STKaiti", "KaiTi", serif;
}

@media (min-width: 1920px) {
  .terms-grid {
    grid-template-columns: repeat(auto-fill, minmax(500px, 1fr));
  }

  .term-image {
    height: 300px;
  }
}
</style> 